package 小实验;

//import com.sun.source.tree.Tree;

import javax.swing.tree.TreeNode;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main2 {

    static class TreeNode{
        Integer value;
        TreeNode leftnode;
        TreeNode rightnode;
        TreeNode fathernode;

        public TreeNode(Integer value) {
            this.value = value;
        }

        @Override
        public String toString() {

            return value.toString();
        }

    }

    /*请完成下面这个函数，实现题目要求的功能
    当然，你也可以不按照下面这个模板来作答，完全按照自己的想法来 ^-^
    ******************************开始写代码******************************/
    static String solution(String input) {
//            for (int index=0;index<input.length();index++){
//                if()
//            }
        TreeNode treeroot = new TreeNode(1);//树根
        treeroot.leftnode = new TreeNode(2).fathernode = treeroot.leftnode = new TreeNode(4);
        treeroot.rightnode = new TreeNode(3).fathernode = treeroot;
        TreeNode leftbnode = treeroot;
        while(leftbnode.leftnode!=null){
            leftbnode.leftnode = leftbnode.leftnode;
        }

        while (leftbnode.fathernode!=null){
            System.out.println(leftbnode);
        }
        return "";
    }
    /******************************结束写代码******************************/


    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String res;

        String _input;
        try {
            _input = in.nextLine();
        } catch (Exception e) {
            _input = null;
        }

        res = solution(_input);
        System.out.println(res);
    }

}